package vector;

import general.GeneralTool;

public class Vector2 
{
	public static Vector2 zero()
	{
		return new Vector2(0f, 0f);
	}
	public static Vector2 up()
	{
		return new Vector2(0f, 1f);
	}
	public static Vector2 down() 
	{
		return new Vector2(0f, -1f);
	}
	public static Vector2 left() 
	{
		return new Vector2(-1f, 0f);
	}
	public static Vector2 right() 
	{
		return new Vector2(1f, 0f);
	}
	public static Vector2 random()
	{
		return new Vector2(GeneralTool.randomRange(0, 10000),GeneralTool.randomRange(0,10000)).divise(10000);
	}
	public static Vector2 randomPosition()
	{
		return new Vector2(GeneralTool.randomRange(100, 1820),GeneralTool.randomRange(300,950));
	}
	
	public double x;
	public double y;
	
	public Vector2(double _x,double _y)
	{
		x =_x;
		y =_y;
	}
	public Vector2(Vector2 v)
	{
		x=v.x;
		y=v.y;
	}
	public Vector2(Vector2Int v)
	{
		x=v.x;
		y=v.y;
	}
	
	public Vector2 add(Vector2 v)
	{
		return new Vector2(x+v.x,y+v.y);
	}
	public Vector2 subtract(Vector2 v)
	{
		return new Vector2(x-v.x,y-v.y);
	}
	public Vector2 multiply(double number)
	{
		return new Vector2(x*number,y*number);
	}
	public Vector2 divise(double number)
	{
		if(number == 0)
		{
			throw new java.lang.ArithmeticException();
		}
		return new Vector2(x/number, y/number);
	}
	
	public double sqrmagnitude()
	{
		return x*x + y*y;
	}
	public double magnitude()
	{
		return Math.sqrt(x*x + y*y);
	}
	public Vector2 normalized()
	{
		if(magnitude() == 0f)
			return zero();
		return divise(magnitude());
	}
	
	public double toAngle()
	{
		double rad = Math.atan2(x, y);
		return rad * GeneralTool.Rad2Deg;
	}
	public static Vector2 toDirection(double angle)
	{
		double rad = angle * GeneralTool.Deg2Rad;
		return new Vector2(Math.sin(rad), Math.cos(rad));
	}
	
	@Override
	public String toString() 
	{
		return "(" + String.valueOf(x) + "," + String.valueOf(y) + ")";
	}
}
